; Auto ping one address from the clipboard.
; Author: Roger Xu
; Created: 2011-12-07
; Last Modified: 2011-12-07

; double pipe (||) is set for default value in a combobox.
PING_ADDRESSES := "127.0.0.1||10.58.5.37|proxy.pvgl.sap.corp|proxy.sin.sap.corp|proxy.pal.sap.corp"

localPing(host, count, toFile)
{
    ;FormatTime, OutputVar [, YYYYMMDDHH24MISS, Format]
    FormatTime, now, R

    if toFile
    {
        outputFile := "ping_result-" . host . ".txt"
        Run, %comspec% /c "(echo %now% & ping %host% /n %count%) > %outputFile% && type %outputFile% && pause"
    }
    else
    {
        Run, %comspec% /c "(echo %now% & ping %host% /n %count%) && pause"
    }
}

remotePing(address)
{
    Run, http://www.wipmania.com/pingfrom/%address%/?c=beijing
    ;Run, http://www.wipmania.com/en/ping/%address%/?point=world
}

ping(host, count, toFile)
{
    ;MsgBox Host is %host%.
    localPing(host, count, toFile)
}

;Gui, Add, ControlType [, Options, Text]
Gui, Add, Text, , Please enter the host you want to ping:
Gui, Add, ComboBox, w300 vHost, %PING_ADDRESSES%
; section: Starts a new section and saves this control's position for later use with the xs and ys positioning options
Gui, Add, Text, section, Count:
; ys: Start a new column within this section.
Gui, Add, Edit, ys w100 vCount, 10
; xm: leftmost
Gui, Add, Checkbox, xm vWriteToFile checked, Write to file?
Gui, Add, Button, default gPing, &Ping

;Win+P to show dialog
#p::
;Gui, Show [, Options, Title]
Gui, Show, , Ping
return

; Ping
Ping:
Gui, Submit, NoHide ; Save the input from the user to each control's associated variable.

;GuiControlGet, OutputVar [, Sub-command, ControlID, Param4]
GuiControlGet, host, , Host
GuiControlGet, count, , Count
GuiControlGet, toFile, , WriteToFile

ping(host, count, toFile)
return
